package se.sll.itintegration.catalogue.offer.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 *
 * @author khaleddaham
 */
@SuppressWarnings("PMD.UnusedPrivateField")
@Entity
@Data
@Table(name="contract")
@EqualsAndHashCode(exclude = {"offers"})
public class ContractEntity implements Serializable {
    
    @Id
    @GeneratedValue
    private Long id;
    
    @Column(unique = true)
    private String name;

    @NotNull
    @Column(unique = true, updatable = false)
    private String contractId;
    
    @OneToMany
    private Set<OfferEntity> offers;
    
    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationTime;
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
    @NotNull
    private String sourceSystemHSAId;

    @NotNull
    @Fetch(FetchMode.SELECT)
    @OneToOne(cascade = {CascadeType.DETACH, CascadeType.PERSIST, CascadeType.REMOVE}, mappedBy = "offer", fetch = FetchType.EAGER)
    private CVType type;

    @NotNull
    private Date startDate;

    @NotNull
    private Date endDate;
}